<template>
    <div class="container mCom" id="mCom" style="background:#fff">
        <div class="search-box">
        <div class="btn">
            <el-button size="medium" type="primary" icon="el-icon-circle-plus-outline" @click="handleSetAdd">新增</el-button>
            <el-button size="medium" type="primary" icon="el-icon-delete" @click="handleSetDelete">删除</el-button>
        </div>
        <div class="search">
            <el-input size="medium" clearable v-model="paginationSet.dataSetName" style="width: 240px; margin-right: 10px" placeholder="请输入数据集名称"></el-input>
            <el-button size="medium" type="primary" icon="el-icon-search" @click="handleSetSearch">搜索</el-button>
        </div>
       </div>
       <el-table
      v-loading="loading"
      :data="DataSetList"
       :header-cell-style="{background:'#F5F5F5'}"
      border
      ref="table"
      :row-key="getRowKeys"
      @select="selectRow"
      @select-all='selectAllRow'
      @selection-change="handleSelectionSetChange"
       :tree-props="{children: 'children',hasChildren:'hasChildren'}"
    >
      <!-- <el-table-column label="选择" width="80">
        <template slot-scope="{ row }">
          <el-radio label="row.id" v-model="RowId" @change="cardRadionSetChange(row)"><span></span></el-radio>
        </template>
      </el-table-column> -->
      <el-table-column
      type="selection"
      width="55">
      </el-table-column>
      <el-table-column label="数据集名称"  prop="dataSetName" />
      <el-table-column
        label="数据源名称"
        align="center"
        prop="dbName"
      />
      <el-table-column
        label="数据集类型"
        align="center"
        prop="dataSetType"
        width="100"
      ><template slot-scope="scope">
         {{scope.row.dataSetType==1?'数值':'文本'}}
      </template>
      </el-table-column>
      <el-table-column
        label="数据集用途"
        align="center"
        prop="dataSetUseType"
        width="100"
      >
      <template slot-scope="scope">
        {{scope.row.dataSetUseType==1?'训练':'分析'}}
      </template>
      </el-table-column>
      <el-table-column
        label="目标数据源"
        align="center"
        prop="dataSourceName"
      />
      <el-table-column
        label="数据集表名"
        align="center"
        prop=""
      />
      <el-table-column
        label="结果表名"
        align="center"
        prop="importTableName"
      />
      <el-table-column
        label="导入方式"
        align="center"
        prop="importType"
        width="80"
      >
      </el-table-column>
      <el-table-column
        label="新增时间"
        align="center"
        width="160"
      >
      <template slot-scope="scope">
          {{parseTimeToDate(scope.row.createTime)}}
        </template>
      </el-table-column>
      <el-table-column
        label="更新时间"
        align="center"
        width="160"
      >
      <template slot-scope="scope">
          {{parseTimeToDate(scope.row.createTime)}}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSetUpdate(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.parentId ==0"
            @click="handleSetMan(scope.row)"
            >元数据管理</el-button
          >
          <el-button
            size="mini"
            type="text"
              v-if="scope.row.parentId ==0"
            icon="el-icon-copy-document"
            @click="handleSetDetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagesize">
      <div id="fy" class="block">
        <el-pagination @size-change="handleSizeSetChange" @current-change="handleCurrentSetChange"
        :current-page="paginationSet.pageNumber" :page-sizes="[10, 20, 30, 50]"
        :page-size="paginationSet.pageSize" layout="total, sizes, prev, pager, next"
        :total="total"></el-pagination>
      </div>
    </div>
    <el-dialog :title="title" :visible.sync="openSet" width="800px" append-to-body>
      <el-form ref="dealsData" :model="dealsData" :rules="rules" label-width="110px">
      <el-row>
        <el-col :span="12">
          <div style="text-align:center;margin: 10px 0;"><i class="el-icon-edit"></i>数据来源</div>
          <el-form-item label="数据集名称" prop="dataSetName">
          <el-input  size='mini' @blur="isDataSetName" v-model="dealsData.dataSetName" placeholder="请定义同步到的目标表名"></el-input>
        </el-form-item>
          <el-form-item label="导入方式：" prop="importType">
          <el-select v-model="dealsData.importType" size='mini'   :disabled='isDisabled' placeholder="请选择导入方式"  @change="handleChange">
            <el-option v-for="item in dataImportType" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        <!-- dataSourceName -->
         <el-form-item label="" v-if="dealsData.importType=='SQL'">
          <el-radio-group v-model="dealsData.importTable">
            <el-radio :label="1">单表导入</el-radio>
            <el-radio :label="0">多表导入</el-radio>
          </el-radio-group>
        </el-form-item>
          <!-- <el-form-item label="字段列名：" v-if="deals.importType=='Txt'">
             <el-radio-group v-model="deals.radio">
             <el-radio :label="1">是</el-radio>
             <el-radio :label="0">否</el-radio>
          </el-radio-group>
          </el-form-item> -->
          <el-form-item label="字段分隔符：" prop="delimiter" v-if="(dealsData.importType=='Txt' || dealsData.importType=='CSV')  && isShowUpload">
             <el-select v-model="dealsData.delimiter" size='mini' placeholder="请选择字段分隔符" @change="handleChangedelimiter">
            <el-option v-for="item in separator" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
          </el-form-item>
          <el-form-item prop="otherDelimiter"  v-if="dealsData.delimiter=='other'">
            <el-input size='mini' v-model="dealsData.otherDelimiter"  onkeyup="value=value.replace(/[^\x00-\xff]/g, '')" placeholder="请输入字段分隔符(不能输入中文)"></el-input>
          </el-form-item>
        <el-form-item label="附件：" prop="fileUpload" v-if="dealsData.importType!=='SQL' && isShowUpload">
             <el-upload
             ref="upload"
            class="upload-demo"
                 action="#"
                 :on-remove="handleRemove"
                 :before-remove="beforeRemove"
                  multiple
                 :limit="1"
                 :http-request="uploadHttpRequest"
                 :on-exceed="handleExceed"
                 :before-upload="beforeUpload"
                 :auto-upload="false"
                 :file-list="fileList"
                 >
                 <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>
          <!-- <Uploader v-on:resetForm="handleReset"></Uploader>
          <el-button @click="handleUploader" >解析</el-button> -->
          <!-- <el-upload
                class="mt-10px custom-upload"
                drag
                :action="uploadAction"
                multiple
                :headers="{
                  Authorization: $store.getters.token,
                  token: getToken(),
                  userId: getUserId(),
                  userName: getUserName(),
                  deptId: getDeptId(),
                }"
                :show-file-list="false"
                :on-success="fileUploadSuccess"
                :before-upload="beforeUpload"
                :limit="10"
              >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">
                  上传文件，请<em class="text-[#0181E0]">&nbsp;点击上传</em>
                </div>
                <div class="el-upload__tip" slot="tip">
                  单次批量上传附件，最多只支持10个
                </div>
              </el-upload> -->
       
        </el-form-item>
       
        <el-form-item label="数据源名称：" prop=""  v-if="dealsData.importType=='SQL'">
          <el-select placeholder="请选择数据源名称" size='mini'>
            <!-- <el-option v-for="item in dataType" :key="item.id" :value="item.id" :label="item.name"></el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item label="数据集表名：" prop="" v-if="dealsData.importType=='SQL'">
          <el-select placeholder="请选择数据集表名" size='mini'>
            <!-- <el-option v-for="item in dataType" :key="item.id" :value="item.id" :label="item.name"></el-option> -->
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="数据集名称：" prop="dataSetName">
          <el-input
            maxlength="20"
            size='mini'
            v-model="deals.dataSetName"
            placeholder="请输入数据集名称"
            @blur="isDataSetName"
          />
        </el-form-item> -->
        <el-form-item label="数据集类型：" prop="dataSetType">
          <el-select v-model="dealsData.dataSetType" placeholder="请选择数据集类型" size='mini'>
            <el-option v-for="item in dataSetType" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据集用途：" prop="dataSetUseType">
          <el-select v-model="dealsData.dataSetUseType" placeholder="请选择数据集用途" size='mini'>
            <el-option v-for="item in dataUserType" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <div style="text-align:center;margin: 10px 0;">数据落地</div>
          <el-form-item label="目标数据源：" prop="dataSourceName">
          <el-select v-model="dealsData.dataSourceName" :disabled='isDisabled' placeholder="请选择目标数据源" size='mini'>
            <el-option v-for="item in targetDataSource" :key="item.id" :value="item.name" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结果表名：" prop="importTableName">
          <el-input
          @blur="isTableName"
          :disabled='isDisabled'
            maxlength="20"
            size='mini'
            v-model="dealsData.importTableName"
            placeholder="请输入结果表名"
          />
        </el-form-item>
        <el-form-item label="插入方式：" prop="importMode">
          <el-select v-model="dealsData.importMode"   :disabled='isDisabled' placeholder="请选择插入方式" size='mini'>
            <el-option v-for="item in dataMode" :key="item.id" :value="item.id" :label="item.name"></el-option>
          </el-select>
        </el-form-item>
        </el-col>
      </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" type="primary" @click="submitSetForm">确 定</el-button>
        <el-button size="medium" @click="cancelSet">取 消</el-button>
      </div>
    </el-dialog>
    </div>
</template>
<script>
import {
  getTableList,
  checkIsDataSetName,
  addSetForm,
  checkIsTableName,
  dataSheet,
  generateUpload,
  fileUpload,
  dataNameSearch,
  editInfo,
  getInfoOne,
  delDataArr
} from "../../api/sourceDetail";
import Uploader from "../data_source/source_dialog/add_file/Uploader.vue";
export default {
  name: "dataSet",
  components: {
    Uploader
  },
  data() {
    //自定义输入名称输入校验
    var hasFileUpload = (rule, value, callback) => {
      if (this.$refs.upload.uploadFiles.length < 1) {
        callback(new Error("附件上传不能为空"));
      } else {
        callback();
      }
    };
    var validateTableName = (rule, value, callback) => {
      if (value === "" || value === undefined) {
        callback(new Error("请输入名称"));
      } else {
        if (this.dealsData.importTableName !== "") {
          var that = this;
          var reg = new RegExp(that.regexp.importTableName); //英文字母开头，字母、数字、下划线组成，长度1-32
          if (!reg.test(value)) {
            callback(new Error(that.regexp.importTableNameCheckMsg));
          }
          callback();
        }
        callback();
      }
    };
    return {
      delWant: [],
      isDisabled: false,
      isShowUpload: true,
      dealsData: {
        dataSetName: "",
        importType: "",
        dataSetType: "",
        dataSetUseType: "",
        dataSourceName: "",
        importTableName: "",
        importMode: "",
        delimiter: "",
        encoding: "UTF-8",
        rowSplit: "enter",
        duration: "60",
        previewMode: "ONLY100",
        parentId: "0",
        otherDelimiter: ""
      },
      targetDataSource: [],
      selectedRows: [],
      tableData: [],
      fileType: "",
      fileList: [],
      // 上传模式
      dataMode: [{ name: "覆盖", id: "1" }, { name: "追加", id: "2" }],
      // 数据集用途
      dataUserType: [{ name: "训练", id: "1" }, { name: "分析", id: "2" }],
      // 数据集类型
      dataSetType: [{ name: "数值", id: "1" }, { name: "文本", id: "2" }],
      //分隔符
      separator: [
        { name: "逗号(,)", id: "comma" },
        { name: "分号(;)", id: "semicolon" },
        { name: "任意空格", id: "space" },
        { name: "Tab键", id: "tab" },
        { name: "其他符号", id: "other" }
      ],
      // 导入方式
      dataImportType: [
        { name: "SQL", id: "SQL" },
        { name: "CSV", id: "CSV" },
        { name: "Excel", id: "Excel" },
        { name: "Txt", id: "Txt" }
      ],
      openSet: false,
      DataSetList: [],
      loading: false,
      paginationSet: {
        pageSize: 10,
        pageNumber: 1,
        dataSetName: ""
      },
      total: 0,
      title: "新增",
      //   deals: {
      //     dataSetName: "",
      //     db_url: "jdbc:mysql://<machine_name>:<port>/<dbname>",
      //     data_source_name: "",
      //     db_type: "",
      //     programmeName: "",
      //     port: "",
      //     db_name: "",
      //     user_name: "",
      //     password: ""
      //   },
      //类型数据
      dataType: [
        { name: "mysql", id: "mysql" },
        { name: "oracle", id: "oracle" },
        { name: "postgresql", id: "postgresql" },
        { name: "达梦8", id: "dm" }
      ],
      // 表单规则
      rules: {
        otherDelimiter: [
          { required: true, message: "请输入字段分隔符", trigger: "blur" }
        ],
        delimiter: [
          { required: true, message: "请选择字段分隔符", trigger: "change" }
        ],
        importMode: [
          { required: true, message: "请选择插入方式", trigger: "change" }
        ],
        importTableName: [
          // { required: true, message: "请输入结果表名", trigger: "blur" }
          { required: true, validator: validateTableName, trigger: "blur" }
        ],
        dataSetUseType: [
          { required: true, message: "请选择数据集用途", trigger: "change" }
        ],
        dataSetType: [
          { required: true, message: "请选择数据集类型", trigger: "change" }
        ],
        fileUpload: [
          { required: true, validator: hasFileUpload, message: "附件不能为空" }
        ],
        importType: [
          { required: true, message: "请选择导入方式", trigger: "change" }
        ],
        dataSetName: [
          { required: true, message: "请输入数据集名称", trigger: "blur" }
        ],
        dataSourceName: [
          { required: true, message: "请填写数据库连接url", trigger: "blur" },
          { min: 1, max: 99, message: "长度在 1 到 99 个字符", trigger: "blur" }
        ],
        dbUrl: [
          { required: true, message: "请填写数据库连接url", trigger: "blur" }
        ],
        userName: [
          { required: true, message: "请填写数据库连接用户名", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请填写数据库连接密码", trigger: "blur" }
        ],
        port: [{ required: true, message: "请填写端口号", trigger: "blur" }],
        dataSourceName: [
          { required: true, message: "请选择目标数据源", trigger: "change" }
        ],
        dbName: [
          { required: true, message: "请填写数据库名称", trigger: "blur" }
        ]
      }
    };
  },
  computed: {
    fileUpload: function() {
      return this.$store.state.datasource.fileUpload;
    },
    dataColumnName: function() {
      //数据列头集合
      return this.fileUpload.dataColumnName;
    },
    dataListTitle: function() {
      //数据列头集合
      return this.fileUpload.dataListTitle;
    },
    dataList: function() {
      //数据集合
      return this.fileUpload.dataList;
    },
    deals: function() {
      //条件集合
      return this.fileUpload.deals;
    },
    statue: function() {
      return this.$store.state.datasource.deals.statue;
    },
    fileUploadDialog() {
      return this.statue.fileUpload;
    },
    regexp: function() {
      return this.$store.state.global.regexp;
    }
  },
  created() {
    this.GET_tableList();
  },
  methods: {
    handleChangedelimiter() {
      this.dealsData.otherDelimiter = "";
    },
    // 上传成功的回调
    fileUploadSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.rightUploadList.push(response.data[0]);
        this.form.fileIds = this.rightUploadList.map(item => item.fileId);
      }
    },
    dataNameSearch() {
      dataNameSearch().then(res => {
        if (res.status == "SUCCESS") {
          this.targetDataSource = res.data;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    beforeRemove(file, fileList) {
      if (file && file.status === "success") {
        return this.$confirm(`确定移除 ${file.name}？`);
      }
    },
    beforeUpload(file) {
      if (this.fileType == "") {
        this.$message.error("请先选择导入方式");
        return false;
      }
      if (file.type != "" || file.type != null || file.type != undefined) {
        //截取文件的后缀，判断文件类型
        const FileExt = file.name.replace(/.+\./, "").toLowerCase();
        //计算文件的大小
        const isLt5M = file.size / 1024 / 1024 < 50; //这里做文件大小限制
        //如果大于50M
        if (!isLt5M) {
          this.$showMessage("上传文件大小不能超过 50MB!");
          return false;
        }
        //如果文件类型不在允许上传的范围内
        if (this.fileType == FileExt) {
          return true;
        } else {
          this.$message.error("上传文件格式不正确!");
          return false;
        }
      }
    },
    handleChange(val) {
      this.fileType = val.toLowerCase();
    },
    // 验证数据集是否存在
    isDataSetName(val) {
      if (val.target.value) {
        checkIsDataSetName(val.target.value).then(res => {
          if (res.status === "SUCCESS") {
            this.$message.error("存在相同数据集名称！");
            this.dealsData.dataSetName = "";
          }
        });
      }
    },
    // 验证结果表名
    isTableName(val) {
      checkIsTableName(val.target.value).then(res => {
        if (res.status === "FAIL") {
          this.$message.error("存在相同数据集名称！");
          this.dealsData.dataSetName = "";
        }
      });
    },
    reUpload() {
      //重新上传
      this.$("#ctlBtn").trigger("click");
    },
    handleReset: function() {
      //重置表单
      this.fileUpload.dataColumnName = []; //置空参数设置
      this.fileUpload.dataListTitle = []; //置空预览数据
      this.fileUpload.dataList = []; //置空预览数据
      this.fileUpload.fileItems = []; //置空上传文件列表
      this.fileUpload.uploadFile = ""; //置空文件
      this.fileUpload.fileMD5 = null; //置空fileMD5
      this.dealsData.tableName = ""; //置空表名
      this.dealsData.delimiter = "";
      this.dealsData.rowSplit = "enter";
      this.dealsData.encoding = "UTF-8";
      this.dealsData.duration = 60;
      this.dealsData.previewMode = "ONLY100";
      this.$refs.dealsData.resetFields();
      this.active = 0;
    },
    switchDelimiter(str) {
      let result = str;
      switch (str) {
        case "comma":
          result = ",";
          break;
        case "semicolon":
          result = ";";
          break;
        case "verticalLine":
          result = "|";
          break;
        case "colon":
          result = ":";
          break;
        case "space":
          result = " ";
          break;
        case "tab":
          result = /\t/;
          break;
      }
      return result;
    },
    dealRow(str, splitStr) {
      var result = [];
      var array = str.split(splitStr);
      if (array.length > 0) {
        let tempArray = [];
        let include = false;
        let jump = true;
        array.forEach(item => {
          item = item.trim();
          if (item.startsWith('"') && item.endsWith('"')) {
            result.push(item.replace(/\"/g, ""));
            jump = false;
          } else if (item.startsWith('"') && !item.endsWith('"')) {
            if (!include) {
              include = true;
              tempArray = [];
            }
          } else if (!item.startsWith('"') && item.endsWith('"')) {
            if (include) {
              include = false;
              tempArray.push(item.replace(/\"/g, ""));
              result.push(tempArray.join(splitStr));
              jump = false;
            }
          }
          if (include) {
            tempArray.push(item.replace(/\"/g, ""));
          } else {
            if (jump) {
              result.push(item);
            } else {
              jump = !jump;
            }
          }
        });
      }
      return result;
    },
    deepCopy: function(source) {
      var result;
      source instanceof Array
        ? (result = [])
        : typeof source === "object"
          ? source === null
            ? (result = "")
            : (result = {})
          : (result = source);
      for (var key in source) {
        result[key] =
          typeof source[key] === "object"
            ? this.deepCopy(source[key])
            : source[key];
      }
      return result;
    },
    treeData(data) {
      const cloneData = JSON.parse(JSON.stringify(data)); // 对源数据深度克隆
      return cloneData.filter(father => {
        const branchArr = cloneData.filter(
          child => father.id === child.parentId
        ); // 返回每一项的子级数组
        branchArr.length > 0 ? (father.children = branchArr) : ""; // 如果存在子级，则给父级添加一个children属性，并赋值
        return father.parentId === 0; // 返回第一层
      });
    },
    // 获取表格数据
    GET_tableList() {
      this.loading = true;
      getTableList(this.paginationSet).then(res => {
        this.total = res.data.totalElements;
        this.loading = false;
        this.DataSetList = this.treeData(res.data.content);
      });
    },
    // 父节点含多个子层级
    setChildren(children, type) {
      children.map(item => {
        this.toggleSelection(item, type);
        if (item.children) {
          this.setChildren(item.children, type);
        }
      });
    },
    toggleSelection(row, select) {
      if (row) {
        this.$nextTick(() => {
          this.$refs.table && this.$refs.table.toggleRowSelection(row, select);
        });
      }
    },
    selectAllRow(selection) {
      // 全选
      let isSelect = selection.some(item => {
        let tableDataIds = this.DataSetList.map(data => data.id);
        if (tableDataIds.indexOf(item.id) !== -1) {
          return true;
        } else {
          return false;
        }
      });
      // 全不选
      let isCancel = !this.DataSetList.every(item => {
        let selectIds = selection.map(data => data.id);
        if (selectIds.indexOf(item.id) !== -1) {
          return true;
        } else {
          return false;
        }
      });
      if (isSelect) {
        selection.map(item => {
          if (item.children) {
            this.setChildren(item.children, true);
          }
        });
      }
      if (isCancel) {
        this.DataSetList.map(item => {
          if (item.children) {
            this.setChildren(item.children, false);
          }
        });
      }
    },

    // 勾选父节点时，子层级一起勾选或一起取消勾选
    selectRow(selection, row) {
      let data = selection.some(item => {
        return row.id === item.id;
      });
      if (data) {
        // 勾选节点时
        if (row.children) {
          this.setChildren(row.children, true);
        }
      } else {
        // 取消勾选节点时
        if (row.children) {
          this.setChildren(row.children, false);
        }
      }
    },
    handleSelectionSetChange(val) {
      this.delWant = val.map(item => {
        return item.id;
      });
    },
    getRowKeys(row) {
      //记录每行的key值
      return row.id;
    },
    // 分页
    handleSizeSetChange(val) {
      //选择不同页数时触发事件
      this.paginationSet.pageSize = val; //修改每页条数
      this.GET_tableList();
    },
    handleCurrentSetChange(val) {
      //当前页变化时触发事件
      this.paginationSet.pageNumber = val; //修改当前页
      this.GET_tableList();
    },
    // 搜索按钮
    handleSetSearch() {
      this.GET_tableList();
    },
    // 清除表单
    reForm() {
      this.form = {};
    },
    // 添加
    handleSetAdd() {
      this.dataNameSearch();
      this.title = "新增";
      this.openSet = true;
      // this.$router.push({
      //   name: "sourceDataMan"
      // });
      // this.$router.push({
      //   name: "sourceDataDetail"
      // });
    },
    // 编辑
    handleSetUpdate(item) {
      if (item.parentId == 0) {
        this.title = "编辑";
        this.isShowUpload = false;
        this.isDisabled = true;
        this.openSet = true;
        getInfoOne(item.id).then(res => {
          if (res.status == "SUCCESS") {
            if (res.data.importMode == 1) {
              res.data.importMode = "覆盖";
            } else {
              res.data.importMode = "追加";
            }
            this.dealsData = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        this.$router.push({
          name: "sourceDataMan",
          query: {
            parentId: item.parentId,
            dataSetSourceTable: item.dataSetSourceTable,
            importTableName: item.importTableName,
            tableName: item.dataSetName,
            id: item.id,
            parentId: item.parentId
          }
        });
      }
    },
    // 详情
    handleSetDetail(e) {
      this.$router.push({
        name: "sourceDataDetail",
        query: {
          importTableName: e.importTableName,
          tableName: e.dataSetName,
          id: e.id
        }
      });
    },
    // 源数据管理
    handleSetMan(e) {
      this.$router.push({
        name: "sourceDataMan",
        query: {
          importTableName: e.importTableName,
          tableName: e.dataSetName,
          id: e.id,
          parentId: e.id
        }
      });
    },
    // 删除按钮
    handleSetDelete() {
      this.$confirm("确认删除该数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        delDataArr(this.delWant).then(res => {
          if (res.status == "SUCCESS") {
            this.$message.success("删除成功");
          } else {
            this.$message.success(res.message);
          }
          this.GET_tableList();
        });
      });
    },
    // 取消按钮
    cancelSet() {
      this.fileList = [];
      this.fileType = "";
      this.openSet = false;
      this.dealsData.otherDelimiter = "";
      this.dealsData.importType = "";
      this.dealsData.dataSetName = "";
      this.dealsData.dataSetType = "";
      this.dealsData.dataSetUseType = "";
      this.dealsData.importTableName = "";
      this.dealsData.importMode = "";
      this.isShowUpload = true;
      this.isDisabled = false;
      this.$refs.dealsData.clearValidate();
      this.handleReset();
    },
    uploadHttpRequest(params) {
      let formData = new FormData();
      formData.append("file", params.file);

      // formData.append(
      //   "uploadId",
      //   JSON.stringify(params.deals.uploadId)
      // );
      formData.append("name", params.file.name);
      formData.append("delimiter", this.dealsData.delimiter);

      formData.append("encoding", this.dealsData.encoding);
      formData.append("tableName", this.dealsData.importTableName);
      formData.append("fileType", this.dealsData.importType.toLowerCase());
      //文件上传
      fileUpload(formData).then(res => {
        if (res.status == "SUCCESS") {
          this.$message.success(res.message);
          addSetForm(this.dealsData).then(res => {
            if (res.status == "SUCCESS") {
              this.$message.success(res.message);
              this.cancelSet();
            } else {
              this.$message.error(res.message);
              this.cancelSet();
            }
            this.GET_tableList();
          });
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 表单提交按钮
    submitSetForm() {
      this.$refs.dealsData.validate(valid => {
        if (valid) {
          console.log(
            "%c 🥓  this.dealsData: ",
            "font-size:20px;background-color: #93C0A4;color:#fff;",
            this.dealsData
          );
          if (this.title == "新增") {
            //新增数据
            this.$refs.upload.submit();
          } else {
            //编辑
            if (this.dealsData.importMode == "覆盖") {
              this.dealsData.importMode = 1;
            } else {
              this.dealsData.importMode = 2;
            }
            editInfo(this.dealsData).then(res => {
              if (res.status == "SUCCESS") {
                this.$message.success("编辑成功");
                this.cancelSet();
              } else {
                this.$message.error(res.message);
              }
              this.GET_tableList();
            });
          }
        }
      });
    },
    //重置表单
    reset() {},
    // 单选框选择
    cardRadionSetChange(item) {
      console.log(
        "%c 🍡 row: ",
        "font-size:20px;background-color: #6EC1C2;color:#fff;",
        row
      );
      //  this.$set(item, "reade", false);
    },

    parseTimeToDate: function(timeStep) {
      //将时间戳转成yyyy-mm-dd hh:mm:ss
      if (timeStep == null || timeStep == "" || timeStep == 0) {
        return null;
      }
      var time = new Date(timeStep);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return (
        y +
        "-" +
        this.addNum(m) +
        "-" +
        this.addNum(d) +
        " " +
        this.addNum(h) +
        ":" +
        this.addNum(mm) +
        ":" +
        this.addNum(s)
      );
    },
    addNum: function(m) {
      return m < 10 ? "0" + m : m;
    }
  }
};
</script>
<style scoped>
.container .search-box {
  width: 100%;
  height: 30px;
  line-height: 30px;
  margin: 20px 0;
  display: flex;
  justify-content: space-between;
}
/deep/ .el-table__row div {
  display: inline-block;
  margin-right: 5px;
}
/deep/ .el-dialog__body .el-select {
  display: block;
  width: 100%;
}
/deep/.el-table div .el-table__indent {
  padding-left: 28px !important;
}
</style>
